<!--督导结果统计-->
<template>
  <div class="wrapper-container">
    <div class="search-container">
      <SelectItem
        :name="'学期'"
        :value="xq"
        @change="
          (e) => {
            xq = e;
          }
        "
        :xqList="xqList"
      ></SelectItem>

      <SelectItem
        v-if="radio4 == '按月份统计'"
        :name="'月份'"
        :value="mounth"
        @change="
          (e) => {
            mounth = e;
          }
        "
        :xqList="mounthList"
      ></SelectItem>
      <SelectItem
        v-if="radio4 == '按月份统计'"
        :name="'状态'"
        :value="state"
        @change="
          (e) => {
            state = e;
          }
        "
        :xqList="stateList"
      ></SelectItem>
      <SelectItem
        :name="'系'"
        :value="system"
        @change="
          (e) => {
            system = e;
          }
        "
        :xqList="systemList"
      ></SelectItem>

      <SelectItem
        :name="'教研室'"
        :value="room"
        @change="
          (e) => {
            room = e;
          }
        "
        :xqList="roomList"
      ></SelectItem>

      <!-- v-if="radio4 == '按督导专家'" -->
      <InputItem
        :name="'教员名称'"
        :value="teacherName"
        @input="
          (e) => {
            teacherName = e;
          }
        "
      ></InputItem>
      <InputItem
        v-if="radio4 == '按月份统计'"
        :name="'督导专家'"
        :value="spacia"
        @input="
          (e) => {
            spacia = e;
          }
        "
      ></InputItem>

      <div class="search-button" style="margin-right: 20px">
        <img src="../../../assets/assessment/icon-search.png" alt="" />
        <span>查询</span>
      </div>

      <ButtonItem
        v-if="radio4 == '按月份统计'"
        :name="'批量打印'"
        :link="''"
        :icon="''"
        :buttonColor="'yellow'"
      ></ButtonItem>
    </div>

    <div
      class="search-container"
      style="justify-content: flex-end !important; margin-top: 10px"
    >
      <div class="filter-button">
        <el-radio-group v-model="radio4" size="mini">
          <el-radio-button style="padding-right: 10px" label="按月份统计"
            >按月份统计</el-radio-button
          >
          <el-radio-button label="按教员统计">按教员统计</el-radio-button>
        </el-radio-group>
      </div>
    </div>
    <div class="table-container">
      <el-table
        v-if="!tableChangeFlag"
        :data="tableData"
        :span-method="radio4 == '按月份统计' ? null : arraySpanMethod"
        border
        style="width: 100%"
        class="table-data"
        row-class-name="row-class"
        cell-class-name="cell-class"
        header-row-class-name="header-row-class"
        header-cell-class-name="header-cell-class"
      >
        <el-table-column
          v-if="radio4 == '按月份统计'"
          type="selection"
          width="55"
        >
        </el-table-column>
        <el-table-column
          v-if="radio4 == '按教员统计'"
          prop="faculty"
          label="系"
          align="center"
        >
        </el-table-column>
        <el-table-column
          v-if="radio4 == '按教员统计'"
          prop="teachRoom"
          label="教研室"
          align="center"
        >
        </el-table-column>

        <el-table-column
          v-if="radio4 == '按教员统计'"
          prop="teacher"
          label="教员"
          align="center"
        >
        </el-table-column>

        <el-table-column
          v-if="radio4 == '按教员统计'"
          prop="position"
          label="职称"
          align="center"
        >
        </el-table-column>
        <el-table-column
          v-if="radio4 == '按教员统计'"
          prop="score"
          width="120"
          label="督导平均分"
          align="center"
        >
        </el-table-column>

        <el-table-column prop="date" label="日期" align="center">
        </el-table-column>
        <el-table-column prop="week" label="星期" align="center">
        </el-table-column>
        <el-table-column prop="classSessions" label="听课节次" align="center">
        </el-table-column>
        <el-table-column prop="coursename" label="课程名称" align="center">
        </el-table-column>
        <el-table-column prop="teachingClass" label="教学班" align="center">
        </el-table-column>
        <el-table-column prop="classPlace" label="上课地点" align="center">
        </el-table-column>

        <el-table-column
          v-if="radio4 == '按月份统计'"
          prop="instructorUnit"
          label="授课教员单位"
          align="center"
        >
        </el-table-column>
        <el-table-column prop="evaluationScore" label="评价分数" align="center">
        </el-table-column>
        <el-table-column prop="evaluationGrade" label="评价等级" align="center">
        </el-table-column>
        <el-table-column
          prop="supervisionExpert"
          label="督导专家"
          align="center"
        >
        </el-table-column>
        <el-table-column
          v-if="radio4 == '按月份统计'"
          prop="ExpertAffiliation"
          label="督导专家隶属"
          align="center"
        >
        </el-table-column>
        <el-table-column width="200" prop="comment" label="评语" align="center">
          <template slot-scope="scope">
            <el-tooltip
              v-if="scope.row.comment && scope.row.comment.length > 36"
              style="max-width: 300px"
              effect="light"
              placement="top"
            >
              <div slot="content" class="content-div">
                {{ scope.row.comment }}
              </div>
              <span class="comment-div">{{ scope.row.comment }}</span>
            </el-tooltip>

            <span v-else>{{ scope.row.comment }}</span>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <div
      v-if="!tableChangeFlag"
      class="search-container"
      style="justify-content: space-between !important; margin-top: 10px"
    >
      <ButtonItem
        v-if="radio4 == '按月份统计'"
        :name="'导出Excel'"
        :link="''"
        :icon="'el-icon-download'"
        :buttonColor="'yellow'"
      ></ButtonItem>
      <span>&nbsp;</span>

      <div class="bottom-block">
        <div class="text">授课教员名字后加“*”为课程负责人</div>
      </div>
    </div>
  </div>
</template>

<script>
import SelectItem from "../../../components/SelectItem.vue";
import InputItem from "../../../components/InputItem.vue";
import ButtonItem from "../../../components/ButtonItem.vue";
export default {
  components: {
    SelectItem,
    InputItem,
    ButtonItem,
  },
  data() {
    return {
      tableChangeFlag: false,
      radio4: "按教员统计",
      xq: "2020春",
      xqList: [
        {
          value: "2020春",
          label: "2020春",
        },
        {
          value: "2020夏",
          label: "2020夏",
        },
      ],
      state: "",
      stateList: [
        {
          value: "待提交",
          label: "待提交",
        },
        {
          value: "审批中",
          label: "审批中",
        },
        {
          value: "已审批",
          label: "已审批",
        },
        {
          value: "待审批",
          label: "待审批",
        },
      ],
      spacia: "",
      system: "",
      systemList: [],
      room: "",
      roomList: [],
      mounth: "12月",
      mounthList: [],
      teacherName: "",
      tableData: [
        {
          faculty: "系部1",
          teachRoom: "教研室1",
          position: "初职",
          score: "96",
          date: "2021-02-16",
          week: "星期一",
          classSessions: "1,2,3",
          coursename: "高级数学",
          teacher: "里教员",
          teachingClass: "数学一班",
          classPlace: "教室三",
          instructorUnit: "单位三",
          evaluationScore: "98",
          evaluationGrade: "A",
          supervisionExpert: "里教员",
          ExpertAffiliation: "办公室",
          comment:
            "表现不错表现不错表现不错表现不错表现不错表现不错表现不错表现不错表现不错表现不错表现不错表现不错表现不错表现不错表现不错",
        },
        {
          faculty: "系部1",
          teachRoom: "教研室1",
          position: "初职",
          score: "96",
          date: "2021-02-16",
          week: "星期一",
          classSessions: "1,2,3",
          coursename: "高级数学",
          teacher: "里教员",
          teachingClass: "数学一班",
          classPlace: "教室三",
          instructorUnit: "单位三",
          evaluationScore: "98",
          evaluationGrade: "A",
          supervisionExpert: "里教员",
          ExpertAffiliation: "办公室",
          comment: "表现不错",
        },
        {
          faculty: "系部1",
          teachRoom: "教研室1",
          position: "初职",
          score: "96",
          date: "2021-02-16",
          week: "星期一",
          classSessions: "1,2,3",
          coursename: "高级数学",
          teacher: "里教员",
          teachingClass: "数学一班",
          classPlace: "教室三",
          instructorUnit: "单位三",
          evaluationScore: "98",
          evaluationGrade: "A",
          supervisionExpert: "里教员",
          ExpertAffiliation: "办公室",
          comment: "表现不错",
        },
      ],
    };
  },
  computed: {
    config() {
      return {
        mergeTarget: "id", // 通用依据
        combineProp:
          this.radio4 == "按月份统计"
            ? []
            : [
                // combineProp - 根据mergeTarge 进行合并的单元格属性
                "faculty",
                "teachRoom",
                "teacher",
                "position",
                "score",
              ],
      };
    },
  },
  watch: {
    radio4(val) {
      var _this = this;
      this.tableChangeFlag = true;
      this.mergeRow();
      window.setTimeout(() => {
        _this.tableChangeFlag = false;
      }, 500);
    },
  },
  methods: {
    arraySpanMethod({ row, column }) {
      const span = column["property"] + "-span";
      if (row[span]) {
        return row[span];
      }
    },
    choiceLink(index) {
      this.record = index;
    },
    checkboxChange(e) {
      console.log(e);
    },

    isEmpty(val) {
      return typeof val == "undefined" || val === null || val == "-";
    },
    isObject(val) {
      return Object.prototype.toString.call(val) === "[object Object]";
    },
    mergeRow() {
      let arr = [].concat(this.tableData);
      // arr.splice(index, 0, Object.assign({}, row))

      this.tableData = this.mergeData(arr);
    },
    mergeData(list) {
      // mergeTarge - 合并项依据
      // combineProp - 根据mergeTarge 进行合并的单元格属性
      return this.filterData(this.config, [].concat(list));
    },
    filterData(config, tableData, targetProp) {
      const { mergeTarget, combineProp } = config;
      // 叠加的合并条件
      combineProp.forEach((column) => {
        // 记录合并项
        let combineCount = 1;
        if (this.isObject(column)) {
          return this.filterData.call(this, column, tableData, mergeTarget);
        }
        // 使用倒序遍历
        for (let i = tableData.length - 1; i >= 0; i--) {
          let curr = tableData[i],
            prev = tableData[i - 1];

          if (this.isEmpty(prev)) {
            // 已经循环完毕
            curr[`${column}-span`] = {
              rowspan: combineCount,
              colspan: combineCount >= 1 ? 1 : 0,
            };
            break;
          }

          if (
            prev[targetProp] === curr[targetProp] &&
            prev[mergeTarget] === curr[mergeTarget] &&
            prev[`${column}`] === curr[`${column}`]
          ) {
            ++combineCount;
            curr[`${column}-span`] = {
              rowspan: 0,
              colspan: 0,
            };
          } else {
            curr[`${column}-span`] = {
              rowspan: combineCount,
              colspan: combineCount >= 1 ? 1 : 0,
            };
            prev[`${column}-span`] = {
              rowspan: 1,
              colspan: 1,
            };
            // 前后项不相符时，对combinecount进行重置
            combineCount = 1;
          }
        }
      });
      return tableData;
    },
  },
  created() {
    this.mergeRow();
  },
  mounted() {
    var _this = this;
    var tempArry = Array.from(new Array(12).keys());
    tempArry.forEach(function (e) {
      _this.mounthList.push({
        value: e + 1,
        label: e + 1 + "月",
      });
    });
  },
};
</script>
<style lang="less" scoped>
.search-container {
  justify-content: flex-start !important;
}

.search-button {
  cursor: pointer;
  box-sizing: border-box;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  width: 70px;
  height: 27px;
  background: #f1f8fe;
  border: 1px solid #51aef6;
  border-radius: 6px;

  > span {
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #51aef6;
  }

  > img {
    width: 19px;
    height: 19px;
    margin-right: 4px;
  }
}

.table-container {
  margin-top: 30px;

  .el-table td,
  .el-table th.is-leaf,
  .el-table--border,
  .el-table--group {
    border-color: #c7d7eb;
  }

  .el-table__header tr,
  .el-table__header th {
    padding: 0;
    height: 76px;
    background-color: #edf2f9;
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    line-height: 20px;
    color: #004ca7;
  }

  .el-table__body tr,
  .el-table__body td {
    padding: 0;
    height: 86px;
  }

  .wrapper-button {
    display: flex;
    flex-direction: column;
    align-items: center;

    > div {
      margin-bottom: 8px;
    }
  }
}
</style>

<style lang="less" scoped>
@import "../../../styles/special.less";
.bottom-block {
  display: flex;
  flex-direction: row;
  justify-content: flex-end;
  .text {
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    line-height: 39px;
    color: #004ca7;
  }
}
.content-div {
  max-width: 200px;
}
.comment-div {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}
.table-container::v-deep .el-table__header th {
  border-color: #c7d7eb !important;
  padding-left: 10px;
}
.filter-button::v-deep .el-radio-button .el-radio-button__inner {
  border-radius: 6px !important;
  border: 1px solid rgb(251, 30, 21);
  color: rgb(251, 30, 21);
  background-color: rgb(254, 234, 235);
}
.filter-button::v-deep
  .el-radio-button__orig-radio:checked
  + .el-radio-button__inner {
  border: 1px solid rgb(251, 30, 21);
  color: white;
  background-color: rgb(251, 30, 21);
}
.wrapper-container {
  width: 1711px;
  margin: 0 auto;
}
.table-container {
  margin-top: 30px;

  .table-data {
    width: 100%;
    border: 0.8px solid #004ca7;
    border-radius: 9px;
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #004ca7;
  }
}

.save-button {
  width: 87px;
  height: 36px;
  line-height: 36px;
  background: #fff6ef;
  border: 1px solid #f3b815;
  border-radius: 6px;
  font-size: 18px;
  font-family: Microsoft YaHei;
  font-weight: 400;
  color: #f3b815;
  text-align: center;
  margin: 82px auto;
}

.zuoyou {
  width: 200px;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}
</style>
